﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using FaceSharp.Api.GraphApi;
using FaceSharp.Api.Types;
using Newtonsoft.Json.Linq;

namespace FaceSharp.Api.Objects
{
    public class Likes : GraphBase
    {
        public Likes(IFacebookCore facebookCore): base(facebookCore)
        {
        }
        public IEnumerable<Like> Get(long userId)
        {
            Trace.Write("Begin Request", "GraphApi.GetUserLikes");
            var jObject = MakeGraphRequest(userId.ToString(), "likes");
            var likes = new List<Like>();

            if (jObject != null)
            {
                var jData = (JArray)jObject["data"];
                likes = (from like in jData
                         select new Like()
                         {
                             Id = long.Parse((string)like["id"]),
                             Name = (string)like["name"],
                             Category = (string)like["category"],
                             CreatedTime = (string)like["created_time"]
                         }).ToList();

            }
            Trace.Write("End Request", "GraphApi.GetUserLikes");
            return likes.AsEnumerable();
        }
    }
}